/*
 * Created by Storm Zhang, Feb 11, 2014.
 */

package com.mlz.mlzmall.ui.activity.act.personal.NetworkRequest;


import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;

import com.android.volley.DefaultRetryPolicy;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.mlz.mlzmall.ui.activity.act.base.BaseActivity;


public class VolleyBaseActivity extends BaseActivity {

    protected Context mContext;


    @Override
    protected void onCreate(Bundle savedInstanceState) {

        mContext = this;
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
    }

    @Override
    protected void onRestart() {
        super.onRestart();
    }

    @Override
    protected void onStop() {
        super.onStop();
//        VolleyRequestManager.cancelAll(this);
    }

    protected void executeRequest(Request<?> request) {
        request.setRetryPolicy(new DefaultRetryPolicy(10000, 0,
                DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
        VolleyRequestManager.addRequest(request, this);
    }

    protected Response.ErrorListener errorListener() {
        return new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                ToastUtils.showToast(mContext, VolleyErrorHelper.getMessage(error, mContext));
            }
        };
    }

    int userType;//用户类型

   /* *//**
     * 判断用户登录状态
     *
     * @return
     *//*
    protected boolean islogined() {
        if (EXApplication.getInstance().getLoginUser() != null) {
            return true;
        } else {
            return false;
        }
    }*/

   /* *//**
     * @description 提示未登录
     *//*
    protected void showtips() {
        Toast.makeText(this,
                getResources().getString(R.string.tips_please_login),
                Toast.LENGTH_SHORT).show();
        Intent intent = new Intent(VolleyBaseActivity.this,
                UserLoginActivity.class);
        startActivity(intent);

    }*/

   /* *//**
     * 判断用户是否登记成为企业
     *
     * @return
     *//*
    protected boolean isUserCType() {
        userType = EXApplication.getInstance().getLoginUser().getUserType();
        if (userType != UserBean.USERTYPE_NORMAL && userType == UserBean.USERTYPE_COMPANY) {
            return true;
        } else {
            return false;
        }
    }
*/



   /* *//**
     * 提示用户登记
     *//*
    protected void userNoCompanyType() {
        if (UserBean.USERTYPE_NORMAL == userType) {
        } else if (UserBean.USERTYPE_WORKER == userType) {
            ToastUtils.showToast(getBaseContext(), "您是师傅用户，不能登记");
        } else if (UserBean.USERTYPE_COMPANY == userType) {
        }
    }*/




    /**
     * @return void
     * @throws
     * @description 退出Activity的动画
     * @version 1.0
     * @author 邓浩然
     * @date 2014年8月31日 下午3:46:54
     */
    public void exitActivity() {
        finish();
    }

    /**
     * 跳转Activity并关闭当前的Activity
     *
     * @return void
     * @throws
     * @description
     * @version 1.0
     * @author 邓浩然
     * @date 2014年8月31日 下午3:47:42
     */
    public void enterActivityWithFinish(Intent intent) {
        startActivity(intent);
        finish();
    }

    /**
     * @param intent
     * @return void
     * @throws
     * @description 跳转Activity不finish当前的activity
     * @version 1.0
     * @author 邓浩然
     * @date 2014年8月31日 下午3:50:19
     */
    public void enterAtivityNotFinish(Intent intent) {
        startActivity(intent);
    }

    protected void showErrortoast() {
        ToastUtils.showToast(mContext, "网络不给力，请稍后再试！");
    }

    protected void showErrortoast(String errorInfo) {
        ToastUtils.showToast(mContext, errorInfo);
        // ToastUtils.showToast(mContext, "网络不给力，请稍后再试！");
    }

    protected void showErrortoast(Context mContext, String errorInfo) {
        ToastUtils.showToast(mContext, errorInfo);
        // ToastUtils.showToast(mContext, "网络不给力，请稍后再试！");
    }


}
